package com.hanbit.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ContextAwareImplement implements ContextAware, BeanNameAware, ApplicationContextAware{

	private String beanName;
	private ApplicationContext context;
	
	@Override
	public void setBeanName(String arg0) {
		// TODO Auto-generated method stub
		System.out.println("setBeanName(...) 실행");
		this.beanName = beanName;
	}

	@Override
	public void lifeMessage() {
		// TODO Auto-generated method stub
		System.out.println("life 비지니스 로직 수행 중");
		OtherContextAware other = (OtherContextAware) context.getBean("otherBean");
		other.otherMessage();
	}
	
	// ApplicationContext를 빈에 전달
	public void setApplicationContext(ApplicationContext context) throws BeansException{
		System.out.println("setApplicationContext(..) 실행");
		this.context = context;
	}

}
